package com.example.dllo.baidumusic.adapter;
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG
*/

import android.content.Context;
import android.support.v4.view.PagerAdapter;


import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.dllo.baidumusic.R;
import com.example.dllo.baidumusic.nettool.NetTool;


import java.util.ArrayList;

/**
 * Created by dllo on 16/8/16.
 */
public class LunboViewpagerAdapter extends PagerAdapter implements ViewPager.OnPageChangeListener {
    private Context context;
    private ArrayList<String> strings;
    private ViewPager viewPager;


    public LunboViewpagerAdapter(Context context) {
        this.context = context;
    }

    public void setStrings(ArrayList<String> strings) {
        this.strings = strings;

        notifyDataSetChanged();
    }

    public void setViewPager(ViewPager viewPager) {
        this.viewPager = viewPager;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return strings != null ? Integer.MAX_VALUE : 0;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_lubotu, null);
        ImageView imageView = (ImageView) view.findViewById(R.id.lunbopic_img);
        NetTool netTool = new NetTool();
        netTool.getImage(strings.get(position % strings.size()), imageView);


        container.addView(view);
        viewPager.addOnPageChangeListener(this);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}